using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;

public abstract class EntityBehavior : Mortal
{
	[Serializable]
	public class ColliderMultiplier
	{
		public BoxCollider collider;

		public float multiplier = 1f;
	}

	public enum ParticleType
	{
		NONE = 0,
		LightSmoke = 1,
		HardSmoke = 2,
		Fire = 3,
		Boom = 4,
		ExposionWeapon = 5
	}

	[Serializable]
	public class areaDamage
	{
		public float radius;

		public int damage;
	}

	protected const string particlLightSmoke = "Smoke_light";

	protected const string particlHardSmoke = "Smoke_hard";

	protected const string particlFire = "Smoke_fire";

	protected const string particlBoom = "explosion_car_Destroy";

	public const float shootPointOffset = 1f;

	public float cameraOffset = 7f;

	public float cameraAngle = 10f;

	public VehicleParent trailer;

	public CarType Type;

	public SitPoint[] sitPoints;

	public bool justInstantiated;

	public bool isStopDrive = true;

	[HideInInspector]
	public Vector3 initialPosition;

	[HideInInspector]
	public Quaternion initialRotation;

	[HideInInspector]
	public Transform initialParent;

	[HideInInspector]
	public NavMeshObstacle navMeshCollider;

	[HideInInspector]
	public BoxCollider colliderEnemy;

	[Space(10f)]
	public int startCountBulletCar = 15;

	public bool inWater;

	public bool respawnCar = true;

	public bool carWithWeapon;

	public bool privateCar;

	public bool isAcitveContol = true;

	public bool iCanShoot = true;

	private int _countBulletCar;

	private RacePlayerPlace _racePlaceLabel;

	public float timeBetweenShoot = 1f;

	public float minSpeedToStop = 1f;

	public float predSpeedCarForIgnoreEnemy;

	public float distanceFindCar = 50f;

	public Transform smokePoint;

	public Transform explosionPoint;

	public NJGMapItem iconMiniMap;

	public string nameSpritePreview;

	public Texture previewTexture;

	public Transform cameraPoint;

	public GameObject objCar;

	[SerializeField]
	[Header("Текущая текстура средства")]
	protected Texture textCar;

	[SerializeField]
	[Header("Текстура уничтоженного средства")]
	private Texture textCarDead;

	[Header("Список всех возможных текстур")]
	public Texture[] possibleCarTextures;

	[Header("Названия превью для каждой текстуры соответственно")]
	public List<string> texturePreviewNames;

	public GameObject myCollidePoint;

	public Transform carIndicatorHolder;

	public bool shopCar;

	protected GameObject carIndicator;

	protected List<GameObject> arrInstantiatedParticle = new List<GameObject>();

	protected Material mainMaterial;

	public GameObject particleExposionWeapon;

	public WeaponType weaponType = WeaponType.Car;

	public GameObject particleShoot;

	public GameObject objForDirectionShoot;

	public LayerMask collisionLayer;

	public Rigidbody rigidCar;

	public float CarRespawnTime = 180f;

	public AudioClip soundGetInCar;

	public AudioClip soundGetOutCar;

	public AudioClip soundBonuse;

	[HideInInspector]
	public bool isDestroying;

	public lerpTransformPhoton lerpScript;

	public BCWShadowController bcwShadowController;

	public GameObject pointForShadowProjector;

	public bool carWithoutShadow;

	public bool carWithCustomShadow;

	protected ParticleType lastParticleType;

	public areaDamage[] arrDamage;

	[HideInInspector]
	public bool isShooting;

	public float fireRecoil = 50000f;

	public Rigidbody rigid;

	public float weaponSpreadParam = 0.5f;

	[HideInInspector]
	public float weaponSpread = 0.5f;

	private bool initialized;

	private BaseWeapon _vehicleWeapon;

	private Collider[] _vehicleColliders;

	public AudioSource shootAudioSource;

	public bool onJump;

	public bool onBoost;

	private float _currentBoostAmount;

	public float freeBoostAmount;

	public static string keyPaidBoost = "keyPaidBoost";

	public Coroutine CatForceRespawnCoroutine;

	public float forceRespawnTime;

	private GameObject crownGO;

	public int playersCount
	{
		get
		{
			int num = 0;
			SitPoint[] array = sitPoints;
			foreach (SitPoint sitPoint in array)
			{
				if (!sitPoint.free)
				{
					num++;
				}
			}
			return num;
		}
	}

	public virtual bool isFree
	{
		get
		{
			return playersCount < sitPoints.Length && isStopDrive;
		}
	}

	public int countBulletCar
	{
		get
		{
			return _countBulletCar;
		}
		set
		{
			_countBulletCar = value;
			UpdateAmo();
		}
	}

	public override int health
	{
		get
		{
			return base.health;
		}
		set
		{
			if (health != value)
			{
				base.health = value;
				if (!isFree && getMainHuman() != null && getMainHuman().isMine)
				{
					GameTopWindow.instance.SetEntityHealth(health, maxHealth);
				}
				StartDamageParticle();
			}
		}
	}

	public RacePlayerPlace racePlaceLabel
	{
		get
		{
			if (_racePlaceLabel == null)
			{
				_racePlaceLabel = UnityEngine.Object.Instantiate(Resources.Load<RacePlayerPlace>("Prefabs/RacePlayerPlace"));
				_racePlaceLabel.transform.SetParent(base.transform);
				_racePlaceLabel.transform.localPosition = Vector3.zero + Vector3.up * 3.5f;
				_racePlaceLabel.transform.localScale = Vector3.one;
			}
			return _racePlaceLabel;
		}
	}

	protected BaseWeapon vehicleWeapon
	{
		get
		{
			if (!initialized)
			{
				initialized = true;
				_vehicleWeapon = GetComponentInChildren<BaseWeapon>(true);
				if ((bool)_vehicleWeapon)
				{
					if (Type == CarType.Tank || Type == CarType.Boat)
					{
						StartCoroutine(UpdateIgnoreColliders());
					}
					else
					{
						_vehicleWeapon.Init(collisionLayer, null, null, vehicleColliders);
					}
				}
			}
			return _vehicleWeapon;
		}
	}

	public Collider[] vehicleColliders
	{
		get
		{
			if (_vehicleColliders == null)
			{
				_vehicleColliders = GetComponentsInChildren<Collider>();
			}
			return _vehicleColliders;
		}
	}

	public float currentBoostAmount
	{
		get
		{
			return BCWStorage.Get<float>(keyPaidBoost) + freeBoostAmount;
		}
		set
		{
			if (freeBoostAmount > 0f)
			{
				float num = value - BCWStorage.Get<float>(keyPaidBoost);
				freeBoostAmount = num;
			}
			else if (freeBoostAmount <= 0f)
			{
				freeBoostAmount = 0f;
				if (value <= 0f)
				{
					if (BCWStorage.Get<float>(keyPaidBoost) > 0f)
					{
						BCWStorage.Set(keyPaidBoost, value);
					}
					else
					{
						int num2 = BCWStorage.Get<int>(MarketController.keyCountBoost);
						if (num2 > 0)
						{
							BCWStorage.Set(MarketController.keyCountBoost, num2 - 1);
							BCWStorage.Set(keyPaidBoost, 100f);
						}
						else
						{
							BCWStorage.Set(keyPaidBoost, 0f);
						}
					}
				}
				else
				{
					BCWStorage.Set(keyPaidBoost, value);
				}
			}
			_currentBoostAmount = BCWStorage.Get<float>(keyPaidBoost) + freeBoostAmount;
			if (_currentBoostAmount > 100f)
			{
				_currentBoostAmount = 100f;
			}
		}
	}

	public override void Init()
	{
		base.Init();
		InitEvents(new string[6] { "OnGetIn", "OnGetOut", "EndGetIn", "EndGetOut", "Crush", "PrepareToUse" });
	}

	public override void Awake()
	{
		base.Awake();
		if (objCar == null)
		{
			objCar = base.gameObject;
		}
		navMeshCollider = GetComponent<NavMeshObstacle>();
		if ((bool)navMeshCollider)
		{
			navMeshCollider.enabled = settings.offlineMode;
		}
		initialPosition = base.transform.position;
		initialRotation = base.transform.rotation;
		lerpScript = GetComponent<lerpTransformPhoton>();
		colliderEnemy = GetComponent<BoxCollider>();
		rigidCar = GetComponent<Rigidbody>();
		if (GameController.instance != null)
		{
			GameController.instance.arrAllCar.Add(this);
			if (!base.photonView.isSceneView)
			{
				GameController.instance.viewIdToCar.Add(base.photonView.viewID, this);
			}
		}
		if (GameController.instance.curTypeGame == TypeGame.tanks)
		{
			startCountBulletCar = 100500;
		}
		countBulletCar = startCountBulletCar;
		if (iconMiniMap == null)
		{
			iconMiniMap = GetComponent<NJGMapItem>();
		}
		if (TutorialManager.TuturialWorking())
		{
			UnityEngine.Object.Destroy(iconMiniMap);
		}
		setIconMiniMap(false);
		health = maxHealth;
		if (!privateCar)
		{
			if (CatForceRespawnCoroutine != null)
			{
				PrivateCarManager.instance.StopCoroutine(CatForceRespawnCoroutine);
			}
			CatForceRespawnCoroutine = GameController.instance.StartCoroutine(CarForceRespawn());
		}
		if (Device.indexWeakDevice == 0 && !carWithoutShadow && Type != CarType.Helicopter && Type != CarType.Boat)
		{
			CreateShadowProjector();
		}
	}

	public override void Start()
	{
		base.Start();
		initialParent = base.transform.parent;
	}

	public void CreateShadowProjector()
	{
		if (pointForShadowProjector == null)
		{
			pointForShadowProjector = new GameObject("EntityShadowProjector");
			pointForShadowProjector.transform.SetParent(base.gameObject.transform);
			pointForShadowProjector.transform.localRotation = Quaternion.identity;
			pointForShadowProjector.transform.localRotation = Quaternion.LookRotation(Vector3.down);
			if (Type == CarType.Titan)
			{
				pointForShadowProjector.transform.localPosition = new Vector3(0.82f, 11f, -0.32f);
			}
			else if (Type == CarType.Car)
			{
				pointForShadowProjector.transform.localPosition = new Vector3(0.43f, 6f, -0.9f);
			}
			else if (Type == CarType.Tank)
			{
				pointForShadowProjector.transform.localPosition = new Vector3(0.43f, 5.5f, -1f);
			}
			else if (Type == CarType.Motorcycle)
			{
				pointForShadowProjector.transform.localPosition = new Vector3(0.214f, 3.16f, 0.487f);
			}
		}
		if (bcwShadowController == null)
		{
			bcwShadowController = pointForShadowProjector.AddComponent<BCWShadowController>();
			SetPropertiesForShadow();
		}
		if (Type == CarType.Titan && carWithCustomShadow)
		{
			bcwShadowController.TurnOnEntityShadow(true);
		}
	}

	public void SetPropertiesForShadow()
	{
		if (Type == CarType.Titan)
		{
			bcwShadowController.shadowType = ShadowType.TitanShadow;
			Material shadowMaterial = Resources.Load("Materials/BCWShadowTitan", typeof(Material)) as Material;
			bcwShadowController.shadowMaterial = shadowMaterial;
			bcwShadowController.step = 10;
			bcwShadowController.cone = 80;
			bcwShadowController.TurnOnEntityShadow(true);
		}
		else if (Type == CarType.Car || Type == CarType.Tank)
		{
			bcwShadowController.shadowType = ShadowType.CarShadow;
			Material shadowMaterial2 = Resources.Load("Materials/BCWShadowCar", typeof(Material)) as Material;
			bcwShadowController.shadowMaterial = shadowMaterial2;
			bcwShadowController.step = 15;
			bcwShadowController.cone = 90;
			bcwShadowController.TurnOnEntityShadow(false);
		}
		else if (Type == CarType.Motorcycle)
		{
			bcwShadowController.shadowType = ShadowType.MotoShadow;
			Material shadowMaterial3 = Resources.Load("Materials/BCWShadowMoto", typeof(Material)) as Material;
			bcwShadowController.shadowMaterial = shadowMaterial3;
			bcwShadowController.step = 15;
			bcwShadowController.cone = 60;
			bcwShadowController.TurnOnEntityShadow(true);
		}
	}

	public bool ContainsHumanWithId(int ownerId)
	{
		for (int i = 0; i < sitPoints.Length; i++)
		{
			if (getHuman(i) != null && getHuman(i).photonView.ownerId == ownerId)
			{
				return true;
			}
		}
		return false;
	}

	public Humanoid getMainHuman()
	{
		return getHuman(0);
	}

	public Humanoid getHuman(int n)
	{
		if (n > sitPoints.Length)
		{
			return null;
		}
		return sitPoints[n].inObject;
	}

	public override void OnEnable()
	{
		base.OnEnable();
		if (carWithWeapon)
		{
			iCanShoot = true;
			predSpeedCarForIgnoreEnemy = settings.speedCarForIgnoreEnemy;
		}
	}

	public virtual void ApplyCarUpgradesRPC(string carName)
	{
	}

	public virtual bool setIconMiniMap(bool val)
	{
		if (MapWindow.instance == null)
		{
			return false;
		}
		if (iconMiniMap == null)
		{
			return false;
		}
		iconMiniMap.enabled = val;
		return iconMiniMap.enabled;
	}

	public virtual Transform GetIn(Humanoid player, int n = -1)
	{
		Collider[] componentsInChildren = GetComponentsInChildren<Collider>();
		foreach (Collider collider in componentsInChildren)
		{
			if (collider.tag != "Player")
			{
				collider.tag = "MyVehicle";
			}
		}
		if (n > 0 && n <= sitPoints.Length - 1)
		{
			RiseEvent(this, "OnGetIn", sitPoints[n].showAfterSit, sitPoints[n].inTransform.position.x > player.transform.position.x);
			return sitPoints[n].GetIn(player, delegate(bool showAfterSit, bool left)
			{
				RiseEvent(this, "EndGetIn", showAfterSit, left);
				rigidCar.angularVelocity = Vector3.zero;
			});
		}
		SitPoint[] array = sitPoints;
		foreach (SitPoint sitPoint in array)
		{
			if (!sitPoint.free)
			{
				continue;
			}
			RiseEvent(this, "OnGetIn", sitPoint.showAfterSit, sitPoint.inTransform.InverseTransformPoint(player.transform.position).x < 0f);
			return sitPoint.GetIn(player, delegate(bool showAfterSit, bool left)
			{
				if (player.isMine)
				{
					if (GameController.instance.curTypeGame != TypeGame.race)
					{
						GameTopWindow.instance.SwitchHealthBarToEntity(true);
						GameTopWindow.instance.SetEntityHealth(health, maxHealth);
					}
					else
					{
						GameTopWindow.instance.HideAllHealth();
					}
				}
				RiseEvent(this, "EndGetIn", showAfterSit, left);
				rigidCar.angularVelocity = Vector3.zero;
			});
		}
		return null;
	}

	public virtual Transform GetOut(Humanoid player, bool withAnim)
	{
		onJump = false;
		onBoost = false;
		SitPoint[] array = sitPoints;
		foreach (SitPoint sitPoint in array)
		{
			if (!(sitPoint.inObject == player))
			{
				continue;
			}
			if (player.isMine && GameController.instance.curTypeGame != TypeGame.tanks && GameController.instance.curTypeGame != TypeGame.race && GameController.instance.curTypeGame != TypeGame.WalkingRobots)
			{
				GameTopWindow.instance.SwitchHealthBarToEntity(false);
			}
			return sitPoint.GetOut(delegate(bool show, bool _left)
			{
				RiseEvent(this, "OnGetOut", show, _left);
			}, delegate(bool showAfterSit, bool left)
			{
				base.transform.SetParent(initialParent);
				RiseEvent(this, "EndGetOut", showAfterSit, left);
				Collider[] componentsInChildren = GetComponentsInChildren<Collider>();
				foreach (Collider collider in componentsInChildren)
				{
					if (collider.tag != "Player")
					{
						collider.tag = "Car";
					}
				}
			}, withAnim);
		}
		return null;
	}

	public bool IsFullAmmo()
	{
		return countBulletCar >= startCountBulletCar;
	}

	public virtual void setCountBullets(int val)
	{
		countBulletCar = val;
	}

	[PunRPC]
	public override void GetDamage(int damage, int damageType, int iKillerId, Vector3 killerPosition, Vector3? hitPoint = null)
	{
		if (!isDead && GameController.instance.curTypeGame != TypeGame.race)
		{
			base.GetDamage(damage, damageType, iKillerId, killerPosition, hitPoint);
			if ((float)health < (float)maxHealth * 0.2f && Type != CarType.Titan && GameController.instance.curTypeGame != TypeGame.tanks)
			{
				blowUpCarWithDelay();
			}
		}
	}

	[PunRPC]
	public override void Kill(int iKillerId)
	{
		if (isDead)
		{
			return;
		}
		base.Kill(iKillerId);
		if (!isFree)
		{
			for (int i = 0; i < sitPoints.Length; i++)
			{
				if (getHuman(i) != null)
				{
					BCWDebug.Log("reset last damage");
					getHuman(i).ResetLastDamageInfo(WeaponType.Non, WeaponTypeSpecific.Non, getHuman(i).GetComponent<PlayerBehavior>().indPlayer, -1f, 0f, false, false, false, false, false, false);
					getHuman(i).Kill(iKillerId);
				}
			}
			clearSitPoint();
		}
		if (!settings.offlineMode)
		{
			if (!base.photonView.isMine && GameController.instance.playerScript.photonView.viewID == iKillerId && PrivateCarManager.instance.currentCar != this && !isFree)
			{
				float distance = Vector3.Distance(GameController.instance.playerScript.transform.position, base.transform.position);
				GameplayEventsManager.instance.NewOnlineVehicleDestroy_WithPlayer(weaponType, lastDamageInfo, distance, privateCar);
			}
			if (GameController.instance.playerScript.photonView.viewID == iKillerId)
			{
				GameplayEventsManager.instance.NewOnlineVehicleDestroy(weaponType, lastDamageInfo);
			}
		}
		else
		{
			GameplayEventsManager.instance.NewOfflineVehicleDestroy(weaponType, lastDamageInfo);
		}
		CameraModeControl.instance.ShakeCameraExplosion(base.transform, 30f);
		SwitchTexture(textCarDead, true);
		if (GameController.instance.curTypeGame != TypeGame.tanks || this is TitanBehavior)
		{
			ExpolosionEntity(iKillerId);
		}
		Disable();
	}

	protected virtual void UpdateAmo()
	{
	}

	public void EnableNawMesh(bool val)
	{
		if (!(navMeshCollider == null) && settings.offlineMode)
		{
			if (val)
			{
				navMeshCollider.enabled = true;
			}
			else
			{
				navMeshCollider.enabled = false;
			}
		}
	}

	public void clearSitPoint()
	{
		for (int i = 0; i < sitPoints.Length; i++)
		{
			sitPoints[i].Disable();
		}
	}

	public override void Enable()
	{
		base.Enable();
		base.enabled = true;
		enableSound(true);
		if (settings.offlineMode || base.photonView.isMine)
		{
			respawnCar = false;
			EnableNawMesh(false);
			CancelResetCarWithDelay();
			rigidCar.velocity = Vector3.zero;
			rigidCar.angularVelocity = Vector3.zero;
			rigidCar.isKinematic = false;
			rigidCar.WakeUp();
			if (!isDead)
			{
				CancelResetCarWithDelay();
			}
		}
	}

	public override void Disable()
	{
		base.Disable();
		base.enabled = false;
		enableSound(false);
		if (base.isMine)
		{
			StopAllCoroutines();
			EnableNawMesh(true);
		}
		rigidCar.velocity = Vector3.zero;
		rigidCar.angularVelocity = Vector3.zero;
		rigidCar.isKinematic = true;
		rigidCar.Sleep();
		if ((settings.offlineMode || base.photonView.isMine) && (isDead || initialPosition != base.transform.position) && !privateCar)
		{
			CancelResetCarWithDelay();
			ResetCarWithDelay(CarRespawnTime);
		}
		GetControll(0);
	}

	public virtual void blowUpCarWithDelay()
	{
		if ((settings.offlineMode || base.photonView.isMine) && !IsInvoking("invokBlowUp"))
		{
			Invoke("invokBlowUp", 8f);
		}
	}

	protected virtual void invokBlowUp()
	{
		CancelInvoke("invokBlowUp");
		MyDebug.Log("--->car invokBlowUp isDead=" + isDead);
		if (!isDead)
		{
			if (settings.offlineMode)
			{
				Kill(lastDamageInfo.playerID);
				return;
			}
			Kill(lastDamageInfo.playerID);
			base.photonView.RPC("Kill", PhotonTargets.Others, lastDamageInfo.playerID);
		}
	}

	[PunRPC]
	public virtual void StartDamageParticle()
	{
		ParticleType particleType = ParticleType.NONE;
		particleType = ((health <= 0) ? ParticleType.Boom : (((float)health <= (float)maxHealth * 0.2f) ? ParticleType.Fire : (((float)health <= (float)maxHealth * 0.5f) ? ParticleType.HardSmoke : (((float)health <= (float)maxHealth * 0.75f) ? ParticleType.LightSmoke : ParticleType.NONE))));
		StartDamageParticleByType(particleType);
	}

	protected void StopAllDamagePatricle()
	{
		for (int i = 0; i < arrInstantiatedParticle.Count; i++)
		{
			if (arrInstantiatedParticle[i] != null && PoolManager.instance != null)
			{
				PoolManager.instance.ReturnToPool(arrInstantiatedParticle[i].name, arrInstantiatedParticle[i]);
			}
		}
		arrInstantiatedParticle.Clear();
	}

	protected void StartDamageParticleByType(ParticleType needType)
	{
		string text = string.Empty;
		Vector3 position = smokePoint.position;
		switch (needType)
		{
		case ParticleType.LightSmoke:
			text = "Smoke_light";
			break;
		case ParticleType.HardSmoke:
			text = "Smoke_hard";
			break;
		case ParticleType.Fire:
			text = "Smoke_fire";
			break;
		case ParticleType.Boom:
			position = explosionPoint.position;
			text = "explosion_car_Destroy";
			break;
		case ParticleType.NONE:
			text = string.Empty;
			break;
		}
		if (lastParticleType != needType)
		{
			StopAllDamagePatricle();
			lastParticleType = needType;
			if (!string.IsNullOrEmpty(text))
			{
				GameObject gameObject = PoolManager.instance.TakeFromPool(text, smokePoint);
				gameObject.transform.position = smokePoint.position;
				gameObject.transform.rotation = smokePoint.rotation;
				gameObject.SetActive(true);
				arrInstantiatedParticle.Add(gameObject);
			}
		}
	}

	public virtual void SwitchTexture(string textureName, bool findMaterial)
	{
		if (possibleCarTextures.Select((Texture x) => x.name).Contains(textureName))
		{
			SwitchTexture(possibleCarTextures.FirstOrDefault((Texture x) => x.name == textureName), findMaterial);
		}
	}

	public virtual void SwitchTexture(Texture newTex, bool appliMaterial = false)
	{
		if (this is TitanBehavior || !newTex)
		{
			return;
		}
		if (possibleCarTextures.Contains(newTex))
		{
			textCar = newTex;
		}
		if (appliMaterial && mainMaterial == null)
		{
			mainMaterial = new Material(Shader.Find("Custom/DiffuseColor"));
			mainMaterial.SetFloat("_Alpha", 1f);
			mainMaterial.name = base.gameObject.name;
			Renderer[] componentsInChildren = base.gameObject.GetComponentsInChildren<Renderer>();
			foreach (Renderer renderer in componentsInChildren)
			{
				if (renderer.gameObject.tag != "Weapon")
				{
					renderer.material = mainMaterial;
				}
			}
		}
		if (mainMaterial != null)
		{
			mainMaterial.mainTexture = newTex;
		}
	}

	protected virtual void OnDestroy()
	{
		StopAllDamagePatricle();
		isDestroying = true;
		KickPlayer();
		RemoveFromList();
		TitanTargetDetector.RemoveFromTargetList(this);
		WeaponTargetDetector.RemoveFromTargetList(this);
	}

	protected void KickPlayer()
	{
		if ((bool)getMainHuman())
		{
			((PlayerBehavior)getMainHuman()).OnEndGetOut();
			RiseEvent(this, "EndGetOut", true, true);
			clearSitPoint();
		}
	}

	public void RemoveFromList()
	{
		if (GameController.instance != null)
		{
			GameController.instance.arrAllCar.Remove(this);
			if (!base.photonView.isSceneView)
			{
				GameController.instance.viewIdToCar.Remove(base.photonView.viewID);
			}
		}
	}

	public virtual void ResetCarWithDelay(float timeForReset)
	{
		CancelResetCarWithDelay();
		if (settings.offlineMode)
		{
			ResetCarWithDelayOnline(timeForReset, initialPosition, initialRotation, (!(initialParent == null)) ? initialParent.name : string.Empty);
			return;
		}
		base.photonView.RPC("ResetCarWithDelayOnline", PhotonTargets.All, timeForReset, initialPosition, initialRotation, (!(initialParent == null)) ? initialParent.name : string.Empty);
	}

	public virtual void CancelResetCarWithDelay()
	{
		if (settings.offlineMode)
		{
			CancelResetCarWithDelayOnline();
		}
		else if (base.viewId != 0)
		{
			base.photonView.RPC("CancelResetCarWithDelayOnline", PhotonTargets.All);
		}
	}

	[PunRPC]
	public virtual void ResetCarWithDelayOnline(float timeForReset, Vector3 respCarPosition, Quaternion respcarRotation, string parentName)
	{
		if (!privateCar)
		{
			initialPosition = respCarPosition;
			initialRotation = respcarRotation;
			if (initialParent != null && initialParent.name != parentName)
			{
				initialParent = GameObject.Find(parentName).transform;
			}
			respawnCar = true;
			if (base.isMine)
			{
				Invoke("resetCarOnline", timeForReset);
			}
		}
	}

	public void resetWithDelay()
	{
		if (settings.offlineMode)
		{
			stopResetWithDelay();
			Invoke("reset", CarRespawnTime);
		}
	}

	public void stopResetWithDelay()
	{
		CancelInvoke("reset");
	}

	[PunRPC]
	public void CancelResetCarWithDelayOnline()
	{
		respawnCar = false;
		CancelInvoke("resetCarOnline");
		CancelInvoke("reset");
	}

	public void resetCarOnline()
	{
		if (!base.isMine)
		{
			return;
		}
		lerpScript.incrementHealth++;
		foreach (EntityBehavior item in GameController.instance.arrAllCar)
		{
			if (item.gameObject != base.gameObject && Vector3.Distance(item.transform.position, initialPosition) < 4f)
			{
				ResetCarWithDelay(5f);
				return;
			}
		}
		foreach (PlayerBehavior listPlayer in GameController.instance.listPlayers)
		{
			if (Vector3.Distance(listPlayer.transform.position, initialPosition) < 4f)
			{
				ResetCarWithDelay(5f);
				return;
			}
		}
		if (settings.offlineMode)
		{
			reset();
		}
		else
		{
			base.photonView.RPC("ResetCarRPC", PhotonTargets.All);
		}
	}

	public virtual void OnTriggerEnter(Collider other)
	{
	}

	public virtual void OnTriggerExit(Collider other)
	{
	}

	protected virtual void DemageOnCollision(int resultDamage, int idKiller)
	{
		if (settings.offlineMode)
		{
			GetDamage(resultDamage, 2);
			return;
		}
		base.photonView.RPC("GetDamage", PhotonTargets.All, resultDamage, 2, idKiller);
	}

	public virtual float GetCurrentSpeed()
	{
		return 0f;
	}

	public virtual float GetMaxSpeed()
	{
		return 0f;
	}

	protected virtual void OnCollisionEnter(Collision collision)
	{
		if (base.isMine || collision.gameObject.tag == "ground" || (!TutorialManager.TuturialWorking() && collision.gameObject.tag == "Weapon"))
		{
			return;
		}
		bool flag = false;
		CarBehavior component = collision.gameObject.GetComponent<CarBehavior>();
		HelicopterBehavior component2 = collision.gameObject.GetComponent<HelicopterBehavior>();
		flag = true;
		if (collision.gameObject.tag == "ground")
		{
			flag = false;
		}
		if (!flag)
		{
			return;
		}
		float num = collision.relativeVelocity.magnitude * 2.23694f;
		float num2 = 0f;
		float num3 = 45f;
		int num4 = (int)(num * 0.6f);
		if (collision.contacts.Length > 0)
		{
			float num5 = Vector3.Angle(base.gameObject.transform.forward, collision.contacts[0].normal);
			num5 = Mathf.Abs(num5 - 90f);
			if (num5 < num3)
			{
				return;
			}
			num2 = (num5 - num3) / (90f - num3);
			num4 = (int)((float)num4 * num2);
		}
		if (BCWDebug.isDebugBuild)
		{
		}
		Collider collider = collision.collider;
		string text;
		if (settings.offlineMode)
		{
			text = collider.gameObject.tag;
			if (!text.Equals("ShootTors") || !(GetCurrentSpeed() > settings.speedCarForIgnoreEnemy))
			{
				return;
			}
			EnemyBehavior componentInParent = collider.gameObject.GetComponentInParent<EnemyBehavior>();
			if (GetCurrentSpeed() < settings.speedCarForHighDemageEnemy)
			{
				if (!(GetCurrentSpeed() > 1f) || base.isMine)
				{
					return;
				}
				if (carWithWeapon)
				{
					if (privateCar)
					{
						componentInParent.lowDamageCar(150);
					}
					else
					{
						componentInParent.lowDamageCar(75);
					}
				}
				else
				{
					componentInParent.lowDamageCar(35);
				}
			}
			else
			{
				componentInParent.highDamageCar(10000);
			}
			return;
		}
		text = collider.gameObject.tag;
		if (!text.Equals("ShootTors"))
		{
			return;
		}
		if (BCWDebug.isDebugBuild)
		{
		}
		if (!(GetCurrentSpeed() > settings.speedCarForIgnoreEnemy))
		{
			return;
		}
		PlayerBehavior componentInParent2 = collider.GetComponentInParent<PlayerBehavior>();
		if (componentInParent2 == null || (TDMController.isTeamGameType && componentInParent2.localTeam == TDMController.myTeam))
		{
			return;
		}
		if (GetCurrentSpeed() < settings.speedCarForHighDemageEnemy)
		{
			if (GetCurrentSpeed() > 1f && !base.isMine)
			{
				int num6 = ((!carWithWeapon) ? 35 : ((!privateCar) ? 75 : 150));
				componentInParent2.photonView.RPC("DamageCar", PhotonTargets.All, num6, getMainHuman().viewId, true);
			}
		}
		else
		{
			componentInParent2.photonView.RPC("DamageCar", PhotonTargets.All, 10000, getMainHuman().viewId, false);
		}
	}

	public virtual void enableSound(bool val)
	{
	}

	private void damageAllEnemy(Vector3 pointDamage)
	{
		GameObject[] array = GameObject.FindGameObjectsWithTag("enemy");
		GameObject[] array2 = array;
		foreach (GameObject gameObject in array2)
		{
			areaDamage[] array3 = arrDamage;
			foreach (areaDamage areaDamage in array3)
			{
				if (!(Vector3.Distance(pointDamage, gameObject.transform.position) < areaDamage.radius))
				{
					continue;
				}
				Mortal component = gameObject.GetComponent<Mortal>();
				if (TDMController.isTeamGameType && GameController.instance.curTypeGame != TypeGame.Zombe)
				{
					if (component is EntityBehavior)
					{
						EntityBehavior entityBehavior = component as EntityBehavior;
						PlayerBehavior playerBehavior = entityBehavior.getMainHuman() as PlayerBehavior;
						PlayerBehavior playerBehavior2 = GameController.instance.FindPlayer(entityBehavior.photonView.ownerId);
						if ((entityBehavior.getMainHuman() != null && playerBehavior != null && playerBehavior.localTeam == TDMController.myTeam && !entityBehavior.isMine) || (entityBehavior.privateCar && playerBehavior2 != null && playerBehavior2.localTeam == TDMController.myTeam))
						{
							return;
						}
					}
					else if (component is PlayerBehavior)
					{
						PlayerBehavior playerBehavior3 = component as PlayerBehavior;
						if (playerBehavior3.localTeam == TDMController.myTeam && !playerBehavior3.isMine)
						{
							return;
						}
					}
				}
				GameController.instance.playerScript.SetPlayerLastDamageInfo(component, false);
				component.lastDamageInfo.weaponType = WeaponType.VehicleGun;
				component.lastDamageInfo.weaponTypeSpecific = WeaponTypeSpecific.Non;
				gameObject.GetComponent<EnemyBehavior>().GetDamage(areaDamage.damage, 3);
				break;
			}
		}
	}

	private void damageAllPlayer(Vector3 pointDamage)
	{
		GameObject[] array = GameObject.FindGameObjectsWithTag("Player");
		GameObject[] array2 = array;
		foreach (GameObject gameObject in array2)
		{
			PlayerBehavior component = gameObject.GetComponent<PlayerBehavior>();
			if (!(component != null) || !(component.currentCar == null) || component.inCar || component.inHelic)
			{
				continue;
			}
			if (TDMController.isTeamGameType && GameController.instance.curTypeGame != TypeGame.Zombe && component.localTeam == TDMController.myTeam && !component.isMine)
			{
				break;
			}
			areaDamage[] array3 = arrDamage;
			foreach (areaDamage areaDamage in array3)
			{
				if (Vector3.Distance(pointDamage, gameObject.transform.position) < areaDamage.radius)
				{
					component.SetPlayerLastDamageInfo(component.GetComponent<Mortal>(), false);
					component.lastDamageInfo.weaponType = WeaponType.VehicleGun;
					component.lastDamageInfo.weaponTypeSpecific = WeaponTypeSpecific.Non;
					if (settings.offlineMode)
					{
						component.GetDamage(areaDamage.damage, 3, ownerViewId, base.transform.position);
						break;
					}
					component.photonView.RPC("GetDamage", component.photonView.owner, areaDamage.damage, 3, ownerViewId, base.transform.position, null);
					break;
				}
			}
		}
	}

	private void damageAllCar(Vector3 pointDamage)
	{
		GameObject[] array = GameObject.FindGameObjectsWithTag("Car");
		CarBehavior curCarScript = null;
		GameObject[] array2 = array;
		foreach (GameObject gameObject in array2)
		{
			areaDamage[] array3 = arrDamage;
			foreach (areaDamage areaDamage in array3)
			{
				if (!(Vector3.Distance(pointDamage, gameObject.transform.position) < areaDamage.radius))
				{
					continue;
				}
				curCarScript = gameObject.GetComponent<CarBehavior>();
				if (curCarScript == null)
				{
					continue;
				}
				if (TDMController.isTeamGameType && GameController.instance.curTypeGame != TypeGame.Zombe && ((curCarScript.getMainHuman() != null && (curCarScript.getMainHuman() as PlayerBehavior).localTeam == TDMController.myTeam && !curCarScript.isMine) || (curCarScript.privateCar && GameController.instance.listPlayers.Find((PlayerBehavior p) => p.photonView.owner == curCarScript.photonView.owner).localTeam == TDMController.myTeam)))
				{
					return;
				}
				if (settings.offlineMode)
				{
					curCarScript.GetDamage(areaDamage.damage, 3);
					break;
				}
				curCarScript.photonView.RPC("GetDamage", curCarScript.photonView.owner, areaDamage.damage, 3, ownerViewId);
				break;
			}
		}
	}

	public override Vector3 GetPositionForChargeHit()
	{
		if (sitPoints.Count() == 0)
		{
			return base.GetPositionForChargeHit();
		}
		Vector3 position = sitPoints[0].inTransform.position;
		position.y += 1f;
		return position;
	}

	public virtual void EnablePrivatCar()
	{
	}

	public virtual void ActivateCar(bool val, int playerId = -1, bool dropPlayer = false)
	{
	}

	public virtual void startShoot()
	{
		InvokeRepeating("shootFromCar", 0.03f, 0.3f);
		isShooting = true;
	}

	public virtual void cancelShoot()
	{
		CancelInvoke("shootFromCar");
		isShooting = false;
	}

	public virtual void shootFromCar()
	{
		if (base.isMine && iCanShoot)
		{
			if (isDead)
			{
				cancelShoot();
			}
			else
			{
				shootFromCarOnline();
			}
		}
	}

	private IEnumerator UpdateIgnoreColliders()
	{
		RCC_CarControllerV3 rcc = GetComponent<RCC_CarControllerV3>();
		while (!rcc.endCollectColliders)
		{
			yield return new WaitForSeconds(0.5f);
		}
		_vehicleWeapon.Init(collisionLayer, null, null, vehicleColliders);
	}

	protected virtual void shootFromCarOnline()
	{
		if (!iCanShoot)
		{
			return;
		}
		iCanShoot = false;
		if (countBulletCar > 1)
		{
			if (GameController.instance.playerScript.inHelic)
			{
				FlyWindow.instance.reloadingUI.ReloadAnimation(timeBetweenShoot);
			}
			else
			{
				CarWindow.instance.reloadingUI.ReloadAnimation(timeBetweenShoot);
			}
		}
		else if (GameController.instance.playerScript.inHelic)
		{
			FlyWindow.instance.reloadingUI.NoAmmo(timeBetweenShoot);
		}
		else
		{
			CarWindow.instance.reloadingUI.NoAmmo(timeBetweenShoot);
		}
		Invoke("vklShoot", timeBetweenShoot);
		if (countBulletCar <= 0)
		{
			return;
		}
		countBulletCar--;
		Ray ray = new Ray(objForDirectionShoot.transform.position, objForDirectionShoot.transform.forward);
		RaycastHit hitInfo;
		if (Physics.Raycast(ray, out hitInfo, float.PositiveInfinity, collisionLayer))
		{
			if (vehicleWeapon != null)
			{
				vehicleWeapon.strength = 1f;
				vehicleWeapon.chargerAmmo = 10;
				vehicleWeapon.spreadWeapon = weaponSpread;
				vehicleWeapon.Shoot(hitInfo.point);
				ResetWeaponSpred();
			}
			else
			{
				Debug.LogError("vehicleWeapon not found!");
			}
		}
	}

	public virtual void ResetWeaponSpred()
	{
	}

	private void vklShoot()
	{
		iCanShoot = true;
		if (particleShoot != null)
		{
			particleShoot.SetActive(false);
		}
	}

	private void playSoundBonuse()
	{
		if (VolumeController.IsSoundEnable)
		{
			NGUITools.PlaySound(soundBonuse);
		}
	}

	private void playShootSound()
	{
		if (VolumeController.IsSoundEnable && shootAudioSource != null && shootAudioSource.clip != null)
		{
			shootAudioSource.enabled = true;
			shootAudioSource.PlayOneShot(shootAudioSource.clip);
		}
	}

	public Texture GetCurrentSkin()
	{
		return textCar;
	}

	[PunRPC]
	public void ResetCarRPC()
	{
		reset();
	}

	public virtual void reset()
	{
		DeactivateGrenade();
		DeactivateMine();
		cancelShoot();
		if (!isFree)
		{
			for (int i = 0; i < sitPoints.Length; i++)
			{
				if (getHuman(i) != null)
				{
					BCWDebug.Log("reset last damage");
					getHuman(i).ResetLastDamageInfo(WeaponType.Non, WeaponTypeSpecific.Non, getHuman(i).GetComponent<PlayerBehavior>().indPlayer, -1f, 0f, false, false, false, false, false, false);
					if (GameController.instance.curTypeGame != TypeGame.tanks && GameController.instance.curTypeGame != TypeGame.TDM && GameController.instance.curTypeGame != TypeGame.WalkingRobots)
					{
						getHuman(i).Kill(base.viewId);
					}
				}
			}
			clearSitPoint();
		}
		StopAllCoroutines();
		FullHealthAndArmor();
		SwitchTexture(GetCurrentSkin());
		isDead = false;
		inWater = false;
		isAcitveContol = true;
		countBulletCar = startCountBulletCar;
		if (respawnCar && !privateCar)
		{
			if (BCWDebug.isDebugBuild)
			{
				BCWDebug.Log("reset car " + base.gameObject.name);
			}
			if (GameController.instance.spisokCars != null)
			{
				base.transform.parent = GameController.instance.spisokCars.transform;
			}
			base.transform.position = initialPosition;
			base.transform.rotation = initialRotation;
		}
		Disable();
		base.transform.parent = initialParent;
		respawnCar = false;
		CancelInvoke("invokBlowUp");
		CancelInvoke("reset");
		CancelInvoke("resetCarOnline");
		isImmortal = true;
		Invoke("Resurect", 2f);
	}

	private void Resurect()
	{
		isImmortal = false;
	}

	public void DeactivateGrenade()
	{
		OnChargeExplosionWidhDetonator[] componentsInChildren = GetComponentsInChildren<OnChargeExplosionWidhDetonator>();
		OnChargeExplosionWidhDetonator[] array = componentsInChildren;
		foreach (OnChargeExplosionWidhDetonator onChargeExplosionWidhDetonator in array)
		{
			OnChargeExplosionWidhDetonator.needBlow = false;
			UnityEngine.Object.Destroy(onChargeExplosionWidhDetonator.gameObject);
		}
	}

	public void DeactivateMine()
	{
		OnChargeMine[] componentsInChildren = GetComponentsInChildren<OnChargeMine>();
		OnChargeMine[] array = componentsInChildren;
		foreach (OnChargeMine onChargeMine in array)
		{
			OnChargeMine.needBlow = false;
			UnityEngine.Object.Destroy(onChargeMine.gameObject);
		}
	}

	protected void ExpolosionEntity(int iKillerID)
	{
		Collider[] array = Physics.OverlapSphere(base.transform.position, 5f);
		if (settings.offlineMode || iKillerID <= 0 || GameController.instance.curTypeGame == TypeGame.normal)
		{
			Collider[] array2 = array;
			foreach (Collider collider in array2)
			{
				Mortal componentInParent = collider.GetComponentInParent<Mortal>();
				if (componentInParent != null && !componentInParent.isDead)
				{
					componentInParent.GetDamage(300, 3, iKillerID);
				}
			}
		}
		else
		{
			PhotonView playePhotonViewWithID = GameController.instance.GetPlayePhotonViewWithID(iKillerID);
			if (playePhotonViewWithID != null)
			{
				PunTeams.Team localTeam = GameController.instance.listPlayers.Find((PlayerBehavior p) => p.photonView.viewID == iKillerID).localTeam;
				Collider[] array3 = array;
				foreach (Collider collider2 in array3)
				{
					Mortal componentInParent2 = collider2.GetComponentInParent<Mortal>();
					if (componentInParent2 != null && !componentInParent2.isDead)
					{
						PunTeams.Team localTeam2 = GameController.instance.FindPlayer(componentInParent2.photonView.ownerId).localTeam;
						if (localTeam2 == PunTeams.Team.none || localTeam != localTeam2 || GameController.instance.GetPlayePhotonViewWithID(iKillerID) == componentInParent2.photonView)
						{
							componentInParent2.GetDamage(300, 3, iKillerID);
						}
					}
				}
			}
		}
		Collider[] array4 = array;
		foreach (Collider collider3 in array4)
		{
		}
	}

	private IEnumerator CarForceRespawn()
	{
		while (true)
		{
			yield return new WaitForSeconds(1f);
			if (respawnCar && getMainHuman() == null)
			{
				forceRespawnTime += 1f;
				if (forceRespawnTime > CarRespawnTime)
				{
					if (settings.offlineMode)
					{
						reset();
					}
					else if (PhotonNetwork.isMasterClient)
					{
						base.photonView.RPC("ResetCarRPC", PhotonTargets.All);
					}
					forceRespawnTime = 0f;
				}
			}
			else
			{
				forceRespawnTime = 0f;
			}
		}
	}

	public void ApplyCrown()
	{
		base.photonView.RPC("ApplyCrownRPC", PhotonTargets.All, base.photonView.ownerId);
	}

	[PunRPC]
	public void ApplyCrownRPC(int ownerId)
	{
		GameController.instance.arrAllCar.ForEach(delegate(EntityBehavior car)
		{
			car.HideCrown();
		});
		if (ownerId == base.photonView.ownerId)
		{
			ShowCrown();
		}
	}

	public void ShowCrown()
	{
		if (crownGO == null)
		{
			crownGO = UnityEngine.Object.Instantiate(Resources.Load<GameObject>("RLCrown"));
			crownGO.transform.SetParent(carIndicatorHolder);
			crownGO.transform.localPosition = Vector3.zero;
			crownGO.transform.localScale = Vector3.one;
			crownGO.transform.localRotation = Quaternion.identity;
		}
		crownGO.SetActive(true);
	}

	public void HideCrown()
	{
		if (!(crownGO == null))
		{
			crownGO.SetActive(false);
		}
	}
}
